{extend name="Index/index"}

{block name="main"}

    <!--个个栏目体  开始-->
    <div class="right-wrapper">
        <div class="layui-tab layui-tab-brief" >
            <ul class="layui-tab-title">
                <li class="layui-this font20">我的信息</li>
                <li class="font20">修改密码</li>
            </ul>
            <div class="layui-tab-content">
                <!--个人信息-->
                <div class="layui-tab-item layui-show" lay-filter="docDemoTabBrief">

                        <form class="layui-form"  action="message/update" method="post" enctype="multipart/form-data"
                              name="myform">

                            <!--头像-->
                            <div class="mtl100">
                                <div class="am-popup" id="my-popup">
                                    <div class="am-popup-inner">
                                        <div class="am-popup-hd">
                                            <h4 class="am-popup-title">裁剪图片</h4>
                                            <span data-am-modal-close class="am-close">&times;</span>
                                        </div>
                                        <div class="am-popup-bd">
                                            <!-- 裁剪显示区 -->
                                            <div class="am-margin-bottom-sm" id="clip" style="width: 100%;height: 400px;"></div>

                                            <button type="button" class="am-btn am-btn-primary" id="clipBtn">
                                                裁剪
                                            </button>

                                            <input class="am-hide" type="file" id="file">
                                        </div>
                                    </div>
                                </div>

                                <div>
                                    {if ($message['icon'] == null)}
                                    <img class="am-img-circle am-img-thumbnail" src="/static/personal/img/batman.jpg" id="img-view"  width="100"/>
                                    {else /}
                                    <img class="am-img-circle am-img-thumbnail" src="{$message['icon']}" id="img-view"  width="100"/>
                                    {/if}
                                    <br>
                                    <button type="button" class="am-btn am-btn-primary" id="toggle-file" style="font-size: 16px;">修改头像</button>
                                </div>
                            </div><!--图像结束-->

                            <!--姓名-->
                            <div class="layui-form-item mt20">
                                <label class="layui-form-label">昵称:</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="nickname" required  lay-verify="nicname" placeholder="请输入昵称" autocomplete="off" class="layui-input" value="{$message['nickname']}">
                                    <input type="hidden" name="icon" value="" id="myicon">
                                </div>
                                <div class="layui-form-mid layui-word-aux">只能是汉字、字母、数字和下划线_ ,只能输入3 ~ 6个字符'</div>
                            </div>
                            <!--手机号-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机号:</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="tel" required lay-verify="phone" autocomplete="off" class="layui-input" disabled value="{$message['tel']}">
                                </div>
                            </div>
                            <!--邮箱-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱:</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="email" value="{$message['email']}" required lay-verify="email"  placeholder="请输入您的邮箱" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <!--性别-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">性别:</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="sex" value="1" title="男" {if condition="$message['sex'] eq '1'"}checked{/if} >
                                    <input type="radio" name="sex" value="0" title="女" {if condition="$message['sex'] eq '0'"}checked{/if}>
                                </div>
                            </div>
                            <!--保存修改-->
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="formDemo">保存修改</button>
                                </div>
                            </div>
                        </form>
                </div>
                <!--修改密码 没有写-->
                <div class="layui-tab-item">
                    <form class="layui-form" action="personal/Message/save" method="post" enctype="multipart/form-data"
                          name="myform">
                        <!--确认密码-->
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 120px;"> 当前密码 : </label>
                            <div class="layui-input-inline">
                                <input type="password" name="pwd" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" >
                            </div>


                        </div>
                        <!--新密码-->
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 120px;"> 新密码 : </label>
                            <div class="layui-input-inline">
                                <input type="password" name="newpwd" required lay-verify="pwd" placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">以字母开头，长度在6~18之间，只能包含字母、数字和下划线</div>

                        </div>
                        <!--确认新密码-->
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label" style="width: 120px;">确认新密码 : </label>
                            <div class="layui-input-inline">
                                <input type="password" name="repswd" required  placeholder="请输入密码" autocomplete="off" class="layui-input">
                            </div>

                        </div>
                        <!--手机号-->
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 120px;"> 手机号 : </label>
                            <div class="layui-input-inline">
                                <input type="text" name="tel" required lay-verify="phone" autocomplete="off" class="layui-input phone" disabled value="{$message['tel']}">
                            </div>
                        </div>
                        <!--效验码-->
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label" style="width: 120px;">效验码 : </label>
                            <div class="layui-input-inline" >
                                <input type="text " name="numb"  lay-verify="required" placeholder="请输入六位效验码" autocomplete="off" class="layui-input yzmnum">
                            </div>
                            <div class="layui-form-mid layui-word-aux"><i name="button" class="layui-btn layui-btn-smal yzm">获取短信效验码</i></div>
                        </div>
                        <!--确认修改-->
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button  class="layui-btn" lay-submit lay-filter="formpwd">确认修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div> <!--个个栏目体  结束-->
</div>  <!--main 结束-->
{js href="/static/home/js/jquery.min.js" /}
{js href="/static/home/js/bootstrap.js" /}
{js href="/static/personal/layui/layui.js"}
{js href="/static/personal/jietu/dist/jquery.min.js"}
{js href="/static/personal/jietu/dist/amazeui.min.js"}
{js href="/static/personal/jietu/dist/iscroll-zoom.min.js"}
{js href="/static/personal/jietu/dist/hammer.min.js""}
{js href="/static/personal/jietu/dist/photoClip.min.js"}

<script>
    layui.use(['form','element','layer'], function(){
        // tab 选项卡
        var element = layui.element();
        //form 表单
        var form = layui.form();
        var layer = layui.layer;
        form.verify({
            nicname: function(value) {
                if (value.length < 3 || value.length > 6) {
                    return '昵称至少3个字符,最多6个字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(!/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(value)){
                    return '只能是汉字、字母、数字和下划线_';
                }

            },

            pwd: function(value) {
                if (value.length < 6 || value.length > 18) {
                    return '密码至少6位,最多18位';
                }

                if(!/^[a-zA-Z]\w{5,17}$/.test(value)){
                    return '以字母开头，只能包含字母、数字和下划线';
                }

            },

        });
        $('.yzm').bind('click',function(){
            var id = $('.phone').val();
            showtime(60);
//            console.log(phone);
            $.ajax({
                type:'post',
                url:'message/' + id,
                dateType:'json',
                success:function (data) {
                    if (!data > 0){
                        alert('获取验证码失败!');
                    } else {
                        $('.yzmnum').attr('name','nump');
                        setTimeout(function(){
                            $('.yzmnum').attr('name','numb');
                        },60000);
                    }
                },
                error:function () {

                }

            });
        });

    });
    function showtime(t){
        $('.yzm').addClass('layui-btn-disabled');
        for(i=1;i<=t;i++) {
            window.setTimeout("update_p("+i+","+t+")", i * 1000);
        }

    }

    function update_p(num,t) {
        if(num == t) {
            $('.yzm').removeClass('layui-btn-disabled').text('重新发送') ;
            $('.yzm').removeClass('layui-btn-disabled');
        }
        else {
            printnr = t-num;
            $('.yzm').text('('+printnr+')秒后重新发送') ;
        }
    }
    //上传截图
    $(function() {
        var $clip = $("#clip");
        var $file = $("#file");
        var $imgView = $("#img-view");
        var $popup = $("#my-popup");
        $("#toggle-file").click(function() {
            $file.trigger("click");
            $popup.modal({
                closeViaDimmer: false
            });
        });

        $clip.photoClip({
            width: 250,
            height: 250,
            fileMinSize: 20,
            file: $file,
            ok: "#clipBtn",
            loadStart: function() {
                console.log("照片读取中");
            },
            loadProgress: function(progress) {
                console.log(progress);
            },
            loadError: function() {
                alert("图片加载失败");
            },
            loadComplete: function() {
                console.log("照片读取完成");
            },
            imgSizeMin: function(kbs) {
                alert(kbs, "上传图片过小");
            },
            clipFinish: function(dataURL) {
//                console.log(dataURL);
                document.getElementById("img-view").src = dataURL;
                document.getElementById("myicon").value = dataURL;
                $popup.modal("close");
            }

        });
    })

</script>


{/block}